/*
-------------------------------------------------------------------
BIE is Copyright 2001-2004 Brunswick Corp.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/bie_license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
 */
/*
 * Test.java
 *
 * Created on January 22, 2003, 2:19 PM
 */

package com.webdeninteractive.bie.persistent.privileges;

import java.util.*;

/**
 * TODO: run error
 * @author  jdepons
 */

public class TestUser {
    
    /** Creates a new instance of Test */
    public TestUser() {
    }
    
    /**
     * JVM Args: -Dxbotts.home=D:\eclipse-SDK\WorkspaceBIE\BIE6.0.5\dist
     * 
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception{
    
        String xbottsHome = System.getProperty("xbotts.home");
        System.setProperty("com.webdeninteractive.datasource.PropertiesDir",xbottsHome + "/conf");                
                                
    //user tests
        
        /*
        
        User u = User.create("jdepons","mypassword");
        int oid = u.getOID();
        u.setEmailAddress("jdepons@yahoo.com");
        u.setName("jeff depons");
        u.commitObject();
                
        u = User.create("bob", "allen");
        u.setName("bob johnson");
        u.commitObject();
        
        u = User.create("sam","somePass");
        u.setName("sam smith");
        u.commitObject();
        
        u = User.findByName("sam");
        System.out.println("name = " + u.getName());
        
        ArrayList al = User.findAll();

        System.out.println("found " + al.size());
        
        for (int i=0;i<al.size();i++) {
            u = (User)al.get(i);
            System.out.println("password = " + u.getPassphrase());
        }
        
        u=User.findByName("sam");
        u.remove();
                
        u = User.findByOID(oid);
        System.out.println("name2 = " + u.getName());                                            
    
        //role tests
        
        Role r = Role.create("dashboardUsers");
        oid = r.getOID();
        r.setDescription("dashboard access role");
        r.commitObject();
        
        r = Role.create("routeUsers");
        r.setDescription("route access role");
        r.commitObject();
        
        r = Role.findByName("dashboardUsers");
        System.out.println("name = " + r.getName());

        al = Role.findAll();

        System.out.println("found " + al.size());
        
        for (int j=0;j<al.size();j++) {
            r = (Role)al.get(j);
            System.out.println("description = " + r.getDescription());
        }
        
        r = Role.findByOID(oid);
        System.out.println("name3 = " + r.getName());                                            
                      
        r.remove();
        */
        
        Role r = Role.findByName("routeUsers");
        
        User u = User.findByName("jdepons");
        
        r.removeUser(u);
        //r.addUser(u);
        
        ArrayList users = r.getUsers();
        System.out.println("len = " + users.size());
        
        for (int i =0; i< users.size(); i++) {
            User user = (User)users.get(i);
            
            System.out.println("username = " + user.getUserName());            
        }                
    }    
}
